package org.common.utils.fasttest;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zhouzhibing
 * @date 2024/6/5
 */
public class TestDelay {

    public static void test() {
        ScheduledThreadPoolExecutor scheduledPool = new ScheduledThreadPoolExecutor(2);
        TestTask task = new TestTask();
        ScheduledFuture<?> future = scheduledPool.scheduleWithFixedDelay(task, 5, 5 , TimeUnit.SECONDS);
        task.setFuture(future);
    }

    private static class TestTask implements Runnable {
        private ScheduledFuture<?> future;

        @Override
        public void run() {
            future.cancel(false);
            System.out.println("test task run....");
        }

        public void setFuture(ScheduledFuture<?> future) {
            this.future = future;
        }
    }
}
